package me.send.data.service.provider;

import java.util.Map;
import me.send.business.base.SendVariable;
import me.send.data.service.pojo.Broker;

public class BrokerProvider {
    // brokerid,username,nickname,password,createtime,updatetime,status,telephone,sex,headerpath
    // 提供批量删除功能 2015年7月6日17:03:01
    public String batch_delete(Map<String, Object> parameter) {
	String brokerids = (String) parameter.get("brokerids");
	String sql = "";
	if (brokerids != null && !brokerids.equals("")) {
	    sql = "delete from popuser where popid in (" + brokerids
		  + ")";
	}
	return sql;
    }
    
    public String list_page(Map<String, Object> parameter) {
	// 获取 对象 查询对象 2015年6月23日17:34:01
	Broker broker = (Broker) parameter.get(SendVariable.DATA);
	// 判断下面的字段 是否是null
	String sql = "select * from popuser where 1=1 ";
	if (broker != null) {
	    if (broker.getUsername() != null
		&& !broker.getUsername().equals("")) {
		sql += " and username like '%" + broker.getUsername()
		       + "%'";
	    }
	    if (broker.getLevel() > 0) {
		sql += " and level = " + broker.getLevel() + " ";
	    }
	    if (broker.getSex() > 0) {
		sql += " and sex = " + broker.getSex() + "";
	    }
	}
	sql += " limit #{PAGE.start},#{PAGE.rows} ";
	return sql;
    }
    
    public String count(Map<String, Object> parameter) {
	// 获取 对象 查询对象 2015年6月23日17:34:01
	Broker broker = (Broker) parameter.get(SendVariable.DATA);
	// 判断下面的字段 是否是null
	String sql = "select count(1) as total from popuser where 1=1 ";
	if (broker != null) {
	    if (broker.getUsername() != null
		&& !broker.getUsername().equals("")) {
		sql += " and username like '%" + broker.getUsername()
		       + "%'";
	    }
	    if (broker.getLevel() > 0) {
		sql += " and level = " + broker.getLevel() + " ";
	    }
	    if (broker.getSex() > 0) {
		sql += " and sex = " + broker.getSex() + "";
	    }
	}
	return sql;
    }
}
